<template>
	<view class="container">
		<view class="content">	
			<view v-if="lockList.length>0" class="sub-content">
				<view v-for="(item, index) in lockList" :key="index" class="sub_item_content">
					<view class="sub_item_title">{{item.lockName}}</view>
					<view class="sub_item_info">门锁编号：{{item.lockNo}}</view>
					<view class="sub_item_info">所属企业：{{item.institutionName}}</view>				
				</view>
			</view>	
			<view v-else class="noInformation">
				<view class="no-content">
					<image style="width: 222rpx; height: 146rpx;" src="@/static/room/nocontent.png"
						mode="aspectFit"></image>
					<text class="no-num">暂无门锁，点击右下方“+”按钮 进行添加</text>
				</view>
			</view>
		</view>	
		
		<image class="addIcon" src="@/static/index/addlock.png" mode="aspectFit"
						@click="goAddLock"></image>
	</view>
</template>

<script>
	import util from '@/utils/util.js';
	import {
		getInstallLock
	} from '@/api/mine.js';
	export default {
		data() {
			return {
				userId: this.$userInfo.userId,
				userMob: this.$userInfo.mobile,	
				lockList: [
					// {lockName:'1105室',lockNo:'1215458748',institutionName:'南湖公寓'},
					// {lockName:'1105室',lockNo:'1215458748',institutionName:'南湖公寓'},
					// {lockName:'1105室',lockNo:'1215458748',institutionName:'南湖公寓'},
					// {lockName:'1105室',lockNo:'1215458748',institutionName:'南湖公寓'},
					// {lockName:'1105室',lockNo:'1215458748',institutionName:'南湖公寓'},
					// {lockName:'1105室',lockNo:'1215458748',institutionName:'南湖公寓'},
					// {lockName:'1105室',lockNo:'1215458748',institutionName:'南湖公寓'},
					// {lockName:'1105室',lockNo:'1215458748',institutionName:'南湖公寓'},
					// {lockName:'1105室',lockNo:'1215458748',institutionName:'南湖公寓'},					
				],
			};
		},
		onLoad() {
			this.userId = this.$userInfo.userId;
			this.userMob = this.$userInfo.mobile;
			this.getLockList();
		},
		onUnload() {
			console.log('onUnload');			
		},
		methods: { 			
			async getLockList(){
				const param = {					
					mobile: this.userMob,					
				}				
				let res = await getInstallLock(param);
				if (res.statecode === '0') {
					this.lockList = res.data;
				}
				else 
				{
					util.toast(res.statemsg);
				}
			},			
			//新增门锁
			goAddLock() {
				if (!this.userMob) { // 是否存在用户手机号
					uni.showModal({
						title: '温馨提示',
						content: '请先登录',
						showCancel: false,
						confirmText: '确认',
						success: (res) => {
							if (res.confirm) {
								this.goLogin()
							}
						}
					})
					return;
				}
				uni.navigateTo({
					url: '/pages/mine/addlock/addLockScan'
				})
			}			
		}
	}
</script>

<style lang="less">
	.container {
		display: flex;
		background-color: #F8F8FA;
		height: 100vh;
		box-sizing: border-box;
		
		.content {
			margin-left: 32rpx;
			margin-right: 32rpx;
				.sub_item_content {
					background: #FFFFFF;
					border-radius: 16rpx;
					height: 216rpx;
					display: flex;
					flex-direction: column;
					padding-left: 24rpx;
					margin-top: 20rpx;

					.sub_item_title {
						font-size: 32rpx;					
						font-weight: bold;
						color: #1F2642;
						line-height: 40rpx;
						height: 40rpx;
						padding-top: 32rpx;
						padding-bottom: 8rpx;
					}	
					
					.sub_item_info {
						font-size: 28rpx;
						height: 36rpx;
						font-weight: 400;
						color: #8F92A0;
						line-height: 36rpx;
						margin-top: 16rpx;						
					}	
			}			
		}
		
		.noInformation {
			height: calc(100vh - 350rpx);
		
			.no-content {
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 240rpx 0;
		
				.no-num {
					text-align: center;
					width: 384rpx;
					font-size: 28rpx;
					color: #8F92A0;
					font-weight: 400;
				}
			}
		}
		.addIcon{			
			width: 180rpx;
			height: 180rpx;
			position: fixed;
			right: 9rpx;
			bottom: 104rpx;
		}
	}
</style>